const path = require('path');
const babel = require('rollup-plugin-babel');
import { nodeResolve } from '@rollup/plugin-node-resolve';
import typescript from 'rollup-plugin-typescript2';

const extensions = ['.js', '.ts'];

const resolve = function (...args) {
    return path.resolve(__dirname, ...args);
};

let useIndex = process.env.Index || 0;
console.log('时间:' + new Date().toLocaleTimeString());

let inputs = [
    resolve('./src/client/ClientStart.ts'),
    resolve('./src/server/ServerStart.ts'),
    resolve('./src/client/debug_inject/DebugInject.ts')
];

let outputs = [
    {
        file: './bin/client/js/bundle.js',
        format: 'iife',
        sourcemap: true,
    },
    {
        file: './bin/server/bundle.js',
        format: 'cjs',
        sourcemap: true,
    },
    {
        file: './bin/client/js/debugger.js',
        format: 'iife',
        name: "ltg",
        sourcemap: true,
    }
];

let plugins = [
    [
        nodeResolve({
            extensions,
            modulesOnly: true,
        }),
        // web考虑兼容性使用babel进行转译
        babel({
            exclude: 'node_modules/**',
            extensions,
        }),
    ],
    [
        nodeResolve({
            extensions,
            modulesOnly: true,
        }),
        // web考虑兼容性使用babel进行转译
        babel({
            exclude: 'node_modules/**',
            extensions,
        }),
    ],
    [
        nodeResolve({
            extensions,
            modulesOnly: true,
        }),
        // web考虑兼容性使用babel进行转译
        babel({
            exclude: 'node_modules/**',
            extensions,
        }),
    ]
];

export default {
    input: inputs[useIndex],
    output: outputs[useIndex],
    plugins: plugins[useIndex],
    external: [
        'websocket',
        'http',
    ],
};